<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>css伸缩性布局--flex | mozihao</title><meta name="keywords" content="flex"><meta name="author" content="mozihao"><meta name="copyright" content="mozihao"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="CSS3伸缩性布局&#x3D;&#x3D;flex&#x3D;&#x3D;&#x3D;&#x3D;父盒子&#x3D;&#x3D; section &#x3D;&#x3D;需添加&#x3D;&#x3D; 伸缩布局模式 &#x3D;&#x3D;display: flex;&#x3D;&#x3D;  123456&lt;section&gt;    &lt;div&gt;1&lt;&#x2F;div&gt;    &lt;div&gt;2&lt;&#x2F;div&gt;    &lt;div&gt;3&lt;&#x2F;div&gt;    &lt;div&gt;4&lt;&#x2F;div&amp;gt">
<meta property="og:type" content="article">
<meta property="og:title" content="css伸缩性布局--flex">
<meta property="og:url" content="https://mo_zi_hao.gitee.io/blog/posts/27138/index.html">
<meta property="og:site_name" content="mozihao">
<meta property="og:description" content="CSS3伸缩性布局&#x3D;&#x3D;flex&#x3D;&#x3D;&#x3D;&#x3D;父盒子&#x3D;&#x3D; section &#x3D;&#x3D;需添加&#x3D;&#x3D; 伸缩布局模式 &#x3D;&#x3D;display: flex;&#x3D;&#x3D;  123456&lt;section&gt;    &lt;div&gt;1&lt;&#x2F;div&gt;    &lt;div&gt;2&lt;&#x2F;div&gt;    &lt;div&gt;3&lt;&#x2F;div&gt;    &lt;div&gt;4&lt;&#x2F;div&amp;gt">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://gitee.com/mo_zi_hao/picsBed/raw/master/image/%E6%94%B6%E7%9B%8A%E6%8E%92%E8%A1%8C%E6%A6%9C.jpg">
<meta property="article:published_time" content="2020-05-20T06:18:57.000Z">
<meta property="article:modified_time" content="2021-08-29T15:22:14.596Z">
<meta property="article:author" content="mozihao">
<meta property="article:tag" content="flex">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://gitee.com/mo_zi_hao/picsBed/raw/master/image/%E6%94%B6%E7%9B%8A%E6%8E%92%E8%A1%8C%E6%A6%9C.jpg"><link rel="shortcut icon" href="/blog/img/favicon.png"><link rel="canonical" href="https://mo_zi_hao.gitee.io/blog/posts/27138/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/blog/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/blog/',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"簡"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: true,
  isanchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = { 
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2021-08-29 23:22:14'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    })(window)</script><link rel="stylesheet" type="text/css" href="./css/iconfont.css" media="all"><meta name="generator" content="Hexo 5.4.2"><link rel="alternate" href="/blog/atom.xml" title="mozihao" type="application/atom+xml">
</head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="author-avatar"><img class="avatar-img" src="https://gitee.com/mo_zi_hao/picsBed/raw/master/image/%E6%B5%B7%E8%B4%BC008.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/blog/archives/"><div class="headline">文章</div><div class="length-num">24</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/blog/tags/"><div class="headline">标签</div><div class="length-num">16</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/blog/categories/"><div class="headline">分类</div><div class="length-num">11</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/blog/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/blog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/blog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/blog/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/blog/about/"><i class="fa-fw fas fa-heart"></i><span> 前端知识思维导图</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://gitee.com/mo_zi_hao/picsBed/raw/master/image/%E6%94%B6%E7%9B%8A%E6%8E%92%E8%A1%8C%E6%A6%9C.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/blog/">mozihao</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/blog/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/blog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/blog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/blog/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/blog/about/"><i class="fa-fw fas fa-heart"></i><span> 前端知识思维导图</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">css伸缩性布局--flex</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2020-05-20T06:18:57.000Z" title="发表于 2020-05-20 14:18:57">2020-05-20</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2021-08-29T15:22:14.596Z" title="更新于 2021-08-29 23:22:14">2021-08-29</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/blog/categories/css/">css</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">931</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>3分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="css伸缩性布局--flex"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h2 id="CSS3伸缩性布局"><a href="#CSS3伸缩性布局" class="headerlink" title="CSS3伸缩性布局"></a>CSS3伸缩性布局</h2><h3 id="flex"><a href="#flex" class="headerlink" title="==flex=="></a>==<strong>flex</strong>==</h3><p>==父盒子== section ==需添加== 伸缩布局模式 ==<strong>display: flex;</strong>== </p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">section</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span>&gt;</span>1<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span>&gt;</span>2<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span>&gt;</span>3<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span>&gt;</span>4<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">section</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>==子盒子== div添加分数 ==<strong>flex</strong>==</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-tag">section</span> <span class="selector-tag">div</span><span class="selector-pseudo">:nth-child</span>(<span class="number">1</span>) &#123;</span><br><span class="line">    <span class="attribute">background-color</span>: pink;</span><br><span class="line">    <span class="attribute">flex</span>: <span class="number">1</span>;<span class="comment">/*子盒子添加分数flex:1;不加单位*/</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="selector-tag">section</span> <span class="selector-tag">div</span><span class="selector-pseudo">:nth-child</span>(<span class="number">2</span>) &#123;</span><br><span class="line">    <span class="attribute">background-color</span>: <span class="built_in">rgb</span>(<span class="number">255</span>, <span class="number">231</span>, <span class="number">93</span>);</span><br><span class="line">    <span class="attribute">flex</span>: <span class="number">2</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="selector-tag">section</span> <span class="selector-tag">div</span><span class="selector-pseudo">:nth-child</span>(<span class="number">3</span>) &#123;</span><br><span class="line">    <span class="attribute">background-color</span>: <span class="built_in">rgb</span>(<span class="number">135</span>, <span class="number">241</span>, <span class="number">103</span>);</span><br><span class="line">    <span class="attribute">flex</span>: <span class="number">3</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="selector-tag">section</span> <span class="selector-tag">div</span><span class="selector-pseudo">:nth-child</span>(<span class="number">4</span>) &#123;</span><br><span class="line">    <span class="attribute">background-color</span>: <span class="built_in">rgb</span>(<span class="number">104</span>, <span class="number">228</span>, <span class="number">250</span>);</span><br><span class="line">    <span class="attribute">flex</span>: <span class="number">1</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>效果如图<br><img src="https://img-blog.csdnimg.cn/20190808182554539.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3hpYW9tb2hoaA==,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述"><br><strong>flex简写—&gt; flex: flex-grow、flex-shrink、flex-basis</strong><br><strong>默认值—&gt; flex: 0 1 auto;</strong></p>
<h3 id="flex-1-相当于"><a href="#flex-1-相当于" class="headerlink" title="flex:1  相当于"></a>flex:1  相当于</h3><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="attribute">flex-grow</span>: <span class="number">1</span>;</span><br><span class="line"><span class="attribute">flex-shrink</span>: <span class="number">1</span>;</span><br><span class="line"><span class="attribute">flex-basis</span>: <span class="number">1</span>;</span><br></pre></td></tr></table></figure>
<p>==flex-grow== —&gt;可以来扩展子元素的宽度,设置当前元素应该<strong>占据剩余空间的比例值</strong><br>==flex-shrink== —&gt;定义<strong>收缩比例</strong>,通过设置值来计算收缩空间<br>==flex-basis== —&gt;规定元素的<strong>基准值</strong></p>
<p>==flex-direction==  —&gt;设置子元素的<strong>排列方向</strong>:主轴方向<br>默认主轴方向是row(水平方向):<br><strong>：row</strong>(水平排列方向,从左到右)<br><strong>：row-reverse</strong>(水平排列方向从右到左)<br><strong>：column</strong>（设置主轴方向为纵向，垂直显示）<br><strong>：column-reverse</strong>（与 column 相同，但是以相反的顺序）<br><strong>父盒子</strong>添加<strong>flex-direction: row-reverse;</strong> 实现倒排<br><img src="https://img-blog.csdnimg.cn/20190808183128106.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3hpYW9tb2hoaA==,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述"><br>==flex-wrap== —&gt;控制子元素是否换行显示,默认不换行<br><strong>：nowrap</strong>(不换行)<br><strong>：wrap</strong>(换行)<br><strong>：wrap-reverse</strong>(翻转,原来从上到下,翻转后从下到上排列)<br><strong>父盒子</strong>添加<strong>flex-wrap:wrap-reverse</strong>实现翻转<br><img src="https://img-blog.csdnimg.cn/2019080821060830.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3hpYW9tb2hoaA==,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述"><br>==flex-flow== —&gt;flex-wrap和flex-direction的结合<br><strong>父盒子</strong>添加<strong>flex-flow: wrap-reverse row-reverse</strong> 倒排+翻转<br><img src="https://img-blog.csdnimg.cn/20190808214342402.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3hpYW9tb2hoaA==,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述"><br><strong>控制子项目的排列顺序:</strong> <strong>order</strong><br>==<strong>order</strong>==—-&gt;正序方式排列,从小到大(可以为负数),例order：1;</p>
<h3 id="justify-content"><a href="#justify-content" class="headerlink" title="==justify-content=="></a>==<strong>justify-content</strong>==</h3><p><strong>：flex-start</strong>（<strong>起始位置</strong>开始排列）<br><strong>：flex-end</strong>（<strong>行尾对齐位置</strong>开始排列)<br><strong>：center</strong>（<strong>中点位置</strong>开始排列，<strong>行首和行尾的距离相同</strong>）<br><strong>：space-between</strong>（<strong>行首行尾分别左右对齐</strong>，<strong>中间</strong>相邻元素产生<strong>相同间距</strong>)<br><strong>：space-around</strong>（<strong>中间的间距是行首的边距和行尾的边距的两倍</strong>)<br><strong>：space-evenly</strong>（flex项都沿着主轴<strong>均匀分布</strong>在指定的对齐容器中，<strong>相邻flex项</strong>之间的<strong>间距都完全一样</strong>)<br><img src="https://img-blog.csdnimg.cn/20190809143332301.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3hpYW9tb2hoaA==,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述"></p>
<h3 id="align-content-（针对flex容器里面多轴-多行-的情况-）"><a href="#align-content-（针对flex容器里面多轴-多行-的情况-）" class="headerlink" title="==align-content== （针对flex容器里面多轴(多行)的情况 ）"></a>==<strong>align-content</strong>== （针对flex容器里面多轴(多行)的情况 ）</h3><p><strong>：flex-start</strong>（从<strong>起始点开始放置</strong> flex元素）<br><strong>：flex-end</strong>（从<strong>终止点开始放置</strong> flex元素)<br><strong>：center</strong>（将项目<strong>放置在中点</strong>）<br><strong>：space-between</strong>（<strong>均匀分布</strong>项目，第一项与<strong>起始点齐平</strong>，最后一项与<strong>终止点齐平</strong>）<br><strong>：space-around</strong>（<strong>均匀分布</strong>项目，项目在<strong>两端有一半大小</strong>的空间）<br><strong>：space-evenly</strong>（<strong>均匀分布</strong>项目，项目<strong>周围有相等</strong>的空间）<br><strong>：stretch</strong>（默认值，<strong>均匀分布</strong>项目，拉伸‘<strong>自动</strong>’-<strong>大小</strong>的项目以充满容器）<br><img src="https://img-blog.csdnimg.cn/20190809150025836.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3hpYW9tb2hoaA==,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述"></p>
<h3 id="align-items-（针对一行的情况进行排列）"><a href="#align-items-（针对一行的情况进行排列）" class="headerlink" title="==align-items== （针对一行的情况进行排列）"></a>==<strong>align-items</strong>== （针对一行的情况进行排列）</h3><p><strong>：stretch</strong>（默认值，元素被<strong>拉伸以适应容器</strong>，侧轴大小的属性值为’auto’时，则会使项目的边距盒的尺寸尽可能接近所在行的尺寸）<br><strong>：baseline</strong>（<strong>文本基线</strong>对齐）<br><strong>：flex-start</strong>（侧轴方向上<strong>顶对齐</strong>）<br><strong>：flex-end</strong>（侧轴方向上<strong>底对齐</strong>）<br><strong>：center</strong>（侧轴方向上<strong>中对齐</strong>）<br><img src="https://img-blog.csdnimg.cn/20190809151223153.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3hpYW9tb2hoaA==,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述"></p>
<h3 id="align-self"><a href="#align-self" class="headerlink" title="==align-self=="></a>==<strong>align-self</strong>==</h3><p>align-self 属性定义在 ==<strong>flex子项单独</strong>== 在侧轴（纵轴）方向上的<strong>对齐方式</strong>。<br><strong>注意</strong>：<strong>align-self</strong> 属性 ==<strong>可重写</strong>== 灵活容器的 ==<strong>align-items</strong>== 属性。<br><strong>：auto</strong>（默认值，元素继承了它的父容器的 align-items 属性。如果没有父容器则为 “stretch”）<br><strong>：baseline</strong>（元素位于<strong>容器的基线</strong>上）<br><strong>：stretch</strong>（元素被<strong>拉伸以适应容器</strong>）<br><strong>：flex-start</strong>（侧轴方向上<strong>顶对齐</strong>）<br><strong>：flex-end</strong>（侧轴方向上<strong>底对齐</strong>）<br><strong>：center</strong>（侧轴方向上<strong>中对齐</strong>）<br><img src="https://img-blog.csdnimg.cn/20190809152045886.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3hpYW9tb2hoaA==,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述"></p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">mozihao</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://mo_zi_hao.gitee.io/blog/posts/27138/">https://mo_zi_hao.gitee.io/blog/posts/27138/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://mo_zi_hao.gitee.io/blog" target="_blank">mozihao</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/blog/tags/flex/">flex</a></div><div class="post_share"><div class="social-share" data-image="https://gitee.com/mo_zi_hao/picsBed/raw/master/image/%E6%94%B6%E7%9B%8A%E6%8E%92%E8%A1%8C%E6%A6%9C.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/blog/posts/52053/"><img class="prev-cover" src="https://gitee.com/mo_zi_hao/picsBed/raw/master/image/%E6%94%B6%E7%9B%8A%E6%8E%92%E8%A1%8C%E6%A6%9C.jpg" onerror="onerror=null;src='/blog/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">浅谈css继承及优先级</div></div></a></div><div class="next-post pull-right"><a href="/blog/posts/17678/"><img class="next-cover" src="https://gitee.com/mo_zi_hao/picsBed/raw/master/image/%E6%94%B6%E7%9B%8A%E6%8E%92%E8%A1%8C%E6%A6%9C.jpg" onerror="onerror=null;src='/blog/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">CSS的高级特效----形状（Shapes）</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="card-info-avatar is-center"><img class="avatar-img" src="https://gitee.com/mo_zi_hao/picsBed/raw/master/image/%E6%B5%B7%E8%B4%BC008.jpg" onerror="this.onerror=null;this.src='/blog/img/friend_404.gif'" alt="avatar"/><div class="author-info__name">mozihao</div><div class="author-info__description">if you risk nothing,then you risk anthing</div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/blog/archives/"><div class="headline">文章</div><div class="length-num">24</div></a></div><div class="card-info-data-item is-center"><a href="/blog/tags/"><div class="headline">标签</div><div class="length-num">16</div></a></div><div class="card-info-data-item is-center"><a href="/blog/categories/"><div class="headline">分类</div><div class="length-num">11</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://gitee.com/mo_zi_hao"><i class="iconfont icon-gitee-fill-round"></i><span>我的Gitee</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://gitee.com/mo_zi_hao" target="_blank" title="Gitee"><i class="fab iconfont icon-gitee-fill-round"></i></a><a class="social-icon" href="https://github.com/mmCrazy" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="https://blog.csdn.net/xiaomohhh?spm=1001.2101.3001.5343" target="_blank" title="CSDN"><i class="fab iconfont icon-csdn"></i></a><a class="social-icon" href="https://gitee.com/mo_zi_hao/picsBed/raw/master/image/qrcode_for_gh_d35478eda980_430.jpg" target="_blank" title="公众号"><i class="fab iconfont icon-weixingongzhonghao"></i></a><a class="social-icon" href="mailto:747304031@qq.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">如文章中有哪些错漏，欢迎各位前端的大佬与我交流并指正，谢谢!!</br>邮箱：747304031@qq.com</br>公众号：一起写前端bug</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#CSS3%E4%BC%B8%E7%BC%A9%E6%80%A7%E5%B8%83%E5%B1%80"><span class="toc-number">1.</span> <span class="toc-text">CSS3伸缩性布局</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#flex"><span class="toc-number">1.1.</span> <span class="toc-text">&#x3D;&#x3D;flex&#x3D;&#x3D;</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#flex-1-%E7%9B%B8%E5%BD%93%E4%BA%8E"><span class="toc-number">1.2.</span> <span class="toc-text">flex:1  相当于</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#justify-content"><span class="toc-number">1.3.</span> <span class="toc-text">&#x3D;&#x3D;justify-content&#x3D;&#x3D;</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#align-content-%EF%BC%88%E9%92%88%E5%AF%B9flex%E5%AE%B9%E5%99%A8%E9%87%8C%E9%9D%A2%E5%A4%9A%E8%BD%B4-%E5%A4%9A%E8%A1%8C-%E7%9A%84%E6%83%85%E5%86%B5-%EF%BC%89"><span class="toc-number">1.4.</span> <span class="toc-text">&#x3D;&#x3D;align-content&#x3D;&#x3D; （针对flex容器里面多轴(多行)的情况 ）</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#align-items-%EF%BC%88%E9%92%88%E5%AF%B9%E4%B8%80%E8%A1%8C%E7%9A%84%E6%83%85%E5%86%B5%E8%BF%9B%E8%A1%8C%E6%8E%92%E5%88%97%EF%BC%89"><span class="toc-number">1.5.</span> <span class="toc-text">&#x3D;&#x3D;align-items&#x3D;&#x3D; （针对一行的情况进行排列）</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#align-self"><span class="toc-number">1.6.</span> <span class="toc-text">&#x3D;&#x3D;align-self&#x3D;&#x3D;</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/blog/posts/1/" title="无题"><img src="https://gitee.com/mo_zi_hao/picsBed/raw/master/image/%E6%B5%B7%E8%B4%BC4.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="无题"/></a><div class="content"><a class="title" href="/blog/posts/1/" title="无题">无题</a><time datetime="2022-06-05T05:20:17.974Z" title="发表于 2022-06-05 13:20:17">2022-06-05</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/posts/36549/" title="编写可维护的JavaScript (代码习惯)"><img src="https://gitee.com/mo_zi_hao/picsBed/raw/master/image/%E6%B5%B7%E8%B4%BC4.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="编写可维护的JavaScript (代码习惯)"/></a><div class="content"><a class="title" href="/blog/posts/36549/" title="编写可维护的JavaScript (代码习惯)">编写可维护的JavaScript (代码习惯)</a><time datetime="2022-03-19T03:12:42.624Z" title="发表于 2022-03-19 11:12:42">2022-03-19</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/posts/23125/" title="gitlab-cicd"><img src="https://gitee.com/mo_zi_hao/picsBed/raw/master/image/745.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="gitlab-cicd"/></a><div class="content"><a class="title" href="/blog/posts/23125/" title="gitlab-cicd">gitlab-cicd</a><time datetime="2021-12-20T14:00:59.661Z" title="发表于 2021-12-20 22:00:59">2021-12-20</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/posts/449/" title="前端js基础"><img src="https://gitee.com/mo_zi_hao/picsBed/raw/master/image/26&amp;gp=0.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="前端js基础"/></a><div class="content"><a class="title" href="/blog/posts/449/" title="前端js基础">前端js基础</a><time datetime="2021-08-29T15:22:14.600Z" title="发表于 2021-08-29 23:22:14">2021-08-29</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/posts/35506/" title="微信小程序"><img src="https://gitee.com/mo_zi_hao/picsBed/raw/master/image/1234.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="微信小程序"/></a><div class="content"><a class="title" href="/blog/posts/35506/" title="微信小程序">微信小程序</a><time datetime="2021-08-29T15:22:14.600Z" title="发表于 2021-08-29 23:22:14">2021-08-29</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By mozihao</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">繁</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div></div><hr/><div id="local-search-results"></div><span class="search-close-button"><i class="fas fa-times"></i></span></div><div id="search-mask"></div></div><div><script src="/blog/js/utils.js"></script><script src="/blog/js/main.js"></script><script src="/blog/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script src="/blog/js/search/local-search.js"></script><div class="js-pjax"></div><script id="click-heart" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/click-heart.min.js" async="async" mobile="false"></script><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script><script src="https://cdn.jsdelivr.net/gh/metowolf/MetingJS@1.2/dist/Meting.min.js"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>